home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
mc51bugs.zip
/
Q37795
< prev
next >
Wrap
Text File
|
1988-11-15
|
1KB
|
65 lines
Q37795 "if" Evaluates Incorrectly Using Unsigned Arithmetic
C Compiler
5.10
MS-DOS
Summary:
When an expression involving unsigned arithmetic is placed inside an
"if" statement, the expression may fail to evaluate correctly.
Microsoft has confirmed this to be a problem in Version 5.10. We are
researching this problem and will post new information as it becomes
available.
More Information:
The following statements illustrate the problem:
#include<stdio.h>
unsigned int a;
main()
{
int b,c;
a=20;
b=1;
c=-1;
a+=;
if((a + (b * c) >= 0)
/* This expression evaluates to false, although the arithmetic
expression should evaluate to 19.*/
{
puts("this should have worked");
}
}
If the following change is made in the above code fragment, the
expression will evaluate correctly:
unsigned int a;
int b, c, d;
.
.
.
d = (a + (b * c));
if ( d >= 0);
The following are other possible workarounds:
1. Casting the expression to integer arithmetic, as follows:
if ( ((int)(a + (b * c))) >= 0 )
2. Change the declaration of the unsigned value, as follows:
int a;
instead of:
unsigned int a;
Keywords: buglist5.10
Updated 88/11/15 06:14